package org.e_gold.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.springframework.beans.BeanUtils;

@Entity
@Table(name = "settled_contract")
public class SettledContract extends ValueObject implements Serializable, Cloneable {

	private static final long serialVersionUID = 1L;

	public static final String RUNNING = "running";

	@Id
	@GeneratedValue
	private Long id;

	@OneToOne
	@JoinColumn(name = "contract_id")
	private Contract contract;

	@Column(name = "bet_amount")
	private Float betAmount;

	@Column(name = "won_amount")
	private Float wonAmount;

	@Column(name = "result_amount")
	private Float resultAmount;

	private Boolean running;

	@Column(name = "current_goal")
	private Integer currentGoal;

	private Boolean won;

	@Column(name = "under_goal")
	private Integer underGoal;

	@Column(name = "bet_slip")
	private String betSlip;

	@Column(name = "settled_play_time")
	private Integer settledPlayTime;

	@Column(name = "settled_total_goals")
	private Integer settledTotalGoals;

	@Transient
	private String home_name;

	@Transient
	private String away_name;

	@Transient
	private int currentTime = 0;

	private Boolean dangerous = false;

	@Override
	public Object clone(){
		try{
			SettledContract sc = new SettledContract();
			BeanUtils.copyProperties(this, sc);

			return sc;
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return this;
	}


	public Boolean getDangerous() {

		return dangerous;
	}

	public void setDangerous(Boolean dangerous) {

		this.dangerous = dangerous;
	}

	public Integer getSettledTotalGoals() {

		return settledTotalGoals;
	}

	public void setSettledTotalGoals(Integer settledTotalGoals) {

		this.settledTotalGoals = settledTotalGoals;
	}

	public Integer getSettledPlayTime() {

		return settledPlayTime;
	}

	public void setSettledPlayTime(Integer settledPlayTime) {

		this.settledPlayTime = settledPlayTime;
	}

	public String getBetSlip() {

		return betSlip;
	}

	public void setBetSlip(String betSlip) {

		this.betSlip = betSlip;
	}

	public Boolean getWon() {
		if(won == null){
			return false;
		}
		return won;
	}

	public void setWon(Boolean won) {

		this.won = won;
	}

	public Integer getUnderGoal() {

		return underGoal;
	}

	public void setUnderGoal(Integer underGoal) {

		this.underGoal = underGoal;
	}

	public Integer getCurrentGoal() {
		if(currentGoal == null){
			return 0;
		}
		return currentGoal;
	}

	public void setCurrentGoal(Integer currentGoal) {

		this.currentGoal = currentGoal;
	}

	public Long getId() {

		return id;
	}

	public void setId(Long id) {

		this.id = id;
	}

	public Contract getContract() {

		return contract;
	}

	public void setContract(Contract contract) {

		this.contract = contract;
	}

	public Float getBetAmount() {

		return betAmount;
	}

	public void setBetAmount(Float betAmount) {

		this.betAmount = betAmount;
	}

	public Float getWonAmount() {

		return wonAmount;
	}

	public void setWonAmount(Float wonAmount) {

		this.wonAmount = wonAmount;
	}

	public Float getResultAmount() {

		return resultAmount;
	}

	public void setResultAmount(Float resultAmount) {

		this.resultAmount = resultAmount;
	}

	public Boolean getRunning() {
		if(running == null){
			return false;
		}
		return running;
	}

	public void setRunning(Boolean running) {

		this.running = running;
	}

	public int getCurrentTime() {
		return currentTime;
	}

	public void setCurrentTime(int currentTime) {
		this.currentTime = currentTime;
	}

	public String getHome_name() {
		return home_name;
	}

	public void setHome_name(String home_name) {
		this.home_name = home_name;
	}

	public String getAway_name() {
		return away_name;
	}

	public void setAway_name(String away_name) {
		this.away_name = away_name;
	}


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof SettledContract)) {
			return false;
		}
		SettledContract other = (SettledContract) obj;
		if (id == null) {
			if (other.id != null) {
				return false;
			}
		} else if (!id.equals(other.id)) {
			return false;
		}
		return true;
	}



}
